package com.qf.testtx;

import com.qf.bean.Zhanghu;
import com.qf.service.ZhanghuService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * 2019/11/15
 * Administrator
 * spring_anno_aop_1113
 * 面向对象面向君  不负代码不负卿
 */
public class TestA {

    private ZhanghuService zhanghuService;

    public void setZhanghuService(ZhanghuService zhanghuService) {
        this.zhanghuService = zhanghuService;
    }

    //线程A  新增数据
     class  A extends  Thread{
             @Override
             public void run()  {
                 System.out.println("A线程开始执行");
                 zhanghuService.inserta();
             }
     }

    //线程B  查询数据
    class  B extends  Thread{
        @Override
        public void run() {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int i = 0; i < 5; i++) {
                List<Zhanghu> zhanghuList = zhanghuService.finda();
                if(i==2){
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("list="+zhanghuList);
            }
        }
    }


    public static void main(String[] args) {
        ApplicationContext app =
                new ClassPathXmlApplicationContext("spring-TX.xml");
        TestA t1 = (TestA) app.getBean("t1");
        A a = t1.new A();
        B b=t1.new B();
        a.start();
        b.start();
    }


}
